#include "VSCollapseRecord.h"
#include "VSStream.h"
#include "VSGraphicInclude.h"
using namespace VSEngine2;
IMPLEMENT_RTTI_NoCreateFun(VSCollapseRecord,VSObject)
VSCollapseRecord::VSCollapseRecord()
{
	m_uiCurRecordID = 0;
	m_uiDesireRecordID = 0;
}
VSCollapseRecord::~VSCollapseRecord()
{
	m_uiCurRecordID = 0;
	m_uiDesireRecordID = 0;
}
IMPLEMENT_RTTI(VSCollapseRecordTri,VSCollapseRecord)
static bool gs_bStreamRegistered_VSCollapseRecordTri= VSCollapseRecordTri::RegisterMainFactory();
bool VSCollapseRecordTri::ms_bRegisterMainFactory = false;
bool VSCollapseRecordTri::RegisterMainFactory()
{
	if (!ms_bRegisterMainFactory)
	{ 
		VSMain::AddInitialFuntion(VSCollapseRecordTri::InitialClassFactory); 
		ms_bRegisterMainFactory = true;
	} 
	return ms_bRegisterMainFactory;

}
bool VSCollapseRecordTri::InitialClassFactory()
{
	ms_ClassFactory.AddElement(ms_Type.GetName(),FactoryFunc);

	return 1;
}
VSObject * VSCollapseRecordTri::FactoryFunc()
{
	return VS_NEW VSCollapseRecordTri;

}
VSCollapseRecordTri::VSCollapseRecordTri()
{

	m_RecordInfo.Clear();
}
VSCollapseRecordTri::~VSCollapseRecordTri()
{
	m_RecordInfo.Clear();
}
unsigned int VSCollapseRecordTri::DiskUse()const
{
	unsigned int Used = VSCollapseRecord::DiskUse();
	for (unsigned int i = 0 ; i < m_RecordInfo.GetNum() ; i++)
	{
		Used += m_RecordInfo[i].DiskUse();
	}
	Used += sizeof(unsigned int);
	return Used;
}
bool VSCollapseRecordTri::Save(VSStream & rStream,unsigned int &iSaveUse)const
{
	if(!VSCollapseRecord::Save(rStream,iSaveUse))
		return 0;

	unsigned int uiRecordNum = m_RecordInfo.GetNum();

	if(!rStream.Write(&uiRecordNum,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	for (unsigned int i = 0 ; i < uiRecordNum ; i++)
	{
		m_RecordInfo[i].Save(rStream,iSaveUse);
	}
	return 1;
}
bool VSCollapseRecordTri::Load(VSStream & rStream,unsigned int &iSaveUse)
{
	if(!VSCollapseRecord::Load(rStream,iSaveUse))
		return 0;

	unsigned int uiRecordNum = 0;

	if(!rStream.Write(&uiRecordNum,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	m_RecordInfo.SetBufferNum(uiRecordNum);
	for (unsigned int i = 0 ; i < uiRecordNum ; i++)
	{
		m_RecordInfo[i].Load(rStream,iSaveUse);
	}

	return 1;
}
bool VSCollapseRecordTri::Clone(const VSObject *pObject,unsigned int uiType)
{
	const VSCollapseRecordTri* Temp = DynamicCast<VSCollapseRecordTri>(pObject); 
	if(!Temp)
		return 0;
	if(VSCollapseRecord::Clone(pObject,uiType))
	{
		m_RecordInfo = Temp->m_RecordInfo;
		return 1;
	}
	else
		return 0;
	
}
bool VSCollapseRecordTri::RecordInfo::Save(VSStream & rStream,unsigned int &iSaveUse)const
{
	if(!rStream.Write(&m_uiKeep,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);
	if(!rStream.Write(&m_uiThrow,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	unsigned int uiMapIndexNum = m_MapIndex.GetNum();
	if(!rStream.Write(&uiMapIndexNum,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	for (unsigned int i = 0 ; i < uiMapIndexNum ; i++)
	{
		if(!rStream.Write(&m_MapIndex[i],sizeof(unsigned int)))
			return 0;
		iSaveUse += sizeof(unsigned int);
	}
	return 1;
}
bool VSCollapseRecordTri::RecordInfo::Load(VSStream & rStream,unsigned int &iSaveUse)
{
	if(!rStream.Read(&m_uiKeep,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);
	if(!rStream.Read(&m_uiThrow,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	unsigned int uiMapIndexNum = 0;
	if(!rStream.Read(&uiMapIndexNum,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	m_MapIndex.SetBufferNum(uiMapIndexNum);
	for (unsigned int i = 0 ; i < uiMapIndexNum ; i++)
	{
		if(!rStream.Read(&m_MapIndex[i],sizeof(unsigned int)))
			return 0;
		iSaveUse += sizeof(unsigned int);
	}
	return 1;
}







IMPLEMENT_RTTI(VSCollapseRecordLine,VSCollapseRecord)
static bool gs_bStreamRegistered_VSCollapseRecordLine= VSCollapseRecordLine::RegisterMainFactory();
bool VSCollapseRecordLine::ms_bRegisterMainFactory = false;
bool VSCollapseRecordLine::RegisterMainFactory()
{
	if (!ms_bRegisterMainFactory)
	{ 
		VSMain::AddInitialFuntion(VSCollapseRecordLine::InitialClassFactory); 
		ms_bRegisterMainFactory = true;
	} 
	return ms_bRegisterMainFactory;

}
bool VSCollapseRecordLine::InitialClassFactory()
{
	ms_ClassFactory.AddElement(ms_Type.GetName(),FactoryFunc);

	return 1;
}
VSObject * VSCollapseRecordLine::FactoryFunc()
{
	return VS_NEW VSCollapseRecordLine;

}
VSCollapseRecordLine::VSCollapseRecordLine()
{

	m_RecordInfo.Clear();
}
VSCollapseRecordLine::~VSCollapseRecordLine()
{
	m_RecordInfo.Clear();
}
unsigned int VSCollapseRecordLine::DiskUse()const
{
	unsigned int Used = VSCollapseRecord::DiskUse();
	for (unsigned int i = 0 ; i < m_RecordInfo.GetNum() ; i++)
	{
		Used += m_RecordInfo[i].DiskUse();
	}
	Used += sizeof(unsigned int);
	return Used;
}
bool VSCollapseRecordLine::Save(VSStream & rStream,unsigned int &iSaveUse)const
{
	if(!VSCollapseRecord::Save(rStream,iSaveUse))
		return 0;

	unsigned int uiRecordNum = m_RecordInfo.GetNum();

	if(!rStream.Write(&uiRecordNum,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	for (unsigned int i = 0 ; i < uiRecordNum ; i++)
	{
		m_RecordInfo[i].Save(rStream,iSaveUse);
	}
	return 1;
}
bool VSCollapseRecordLine::Load(VSStream & rStream,unsigned int &iSaveUse)
{
	if(!VSCollapseRecord::Load(rStream,iSaveUse))
		return 0;

	unsigned int uiRecordNum = 0;

	if(!rStream.Write(&uiRecordNum,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	m_RecordInfo.SetBufferNum(uiRecordNum);
	for (unsigned int i = 0 ; i < uiRecordNum ; i++)
	{
		m_RecordInfo[i].Load(rStream,iSaveUse);
	}

	return 1;
}
bool VSCollapseRecordLine::Clone(const VSObject *pObject,unsigned int uiType)
{
	const VSCollapseRecordLine* Temp = DynamicCast<VSCollapseRecordLine>(pObject); 
	if(!Temp)
		return 0;
	if(VSCollapseRecord::Clone(pObject,uiType))
	{
		m_RecordInfo = Temp->m_RecordInfo;
		return 1;
	}
	else
		return 0;

}
bool VSCollapseRecordLine::RecordInfo::Save(VSStream & rStream,unsigned int &iSaveUse)const
{
	if(!rStream.Write(&m_uiKeep,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);
	if(!rStream.Write(&m_uiThrow,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	if(!rStream.Write(&m_MapIndex,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	if(!rStream.Write(&m_uiLeftEdgeNum,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);
	return 1;
}
bool VSCollapseRecordLine::RecordInfo::Load(VSStream & rStream,unsigned int &iSaveUse)
{
	if(!rStream.Read(&m_uiKeep,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);
	if(!rStream.Read(&m_uiThrow,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);


	if(!rStream.Read(&m_MapIndex,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	if(!rStream.Read(&m_uiLeftEdgeNum,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);
	return 1;
}